// pages/scan/scan.js

var util = require('../../utils/util.js');  

Page({

  /**
   * 页面的初始数据
   */
  data: {
    result: '',
    list:[],
    casArray: ['出去',  '回来'],
    casIndex:0,
  },

  selectTaps() {
    this.setData({
      shows: !this.data.shows,
    });
  },

  name: function (e) {
    this.setData({
      name: e.detail.value
      
    });
  },

  cardid: function (e) {
    this.setData({
      cardid: e.detail.value
    });
  },

  houseid: function (e) {
    this.setData({
      houseid: e.detail.value
    });
  },

  temperature: function (e) {
    this.setData({
      temperature: e.detail.value
    });
  },

  in_orout: function (e) {
    this.setData({
      in_orout: e.detail.value
    });
  },

  // 点击下拉列表
  optionTaps(e) {
    let Indexs = e.currentTarget.dataset.index; //获取点击的下拉列表的下标
    console.log(Indexs)
    this.setData({
      indexs: Indexs,
      shows: !this.data.shows
    });

  },

  get:function () {  

    // 调用函数时，传入new Date()参数，返回值是日期和时间  
    
    var time = util.formatTime(new Date());  
    
    // 再通过setData更改Page()里面的data，动态更新页面的数据  
    
    this.setData({  
    
          time: time,
         
        });  
    
      }  ,

      loginForm: function (data) {
        var that = this;   
        var name = data.detail.value.name
        var houseid = data.detail.value.houseid
        var cardid = data.detail.value.cardid
        var temperature = data.detail.value.temperature
        var in_orout = data.detail.value.in_orout
        var outtime = data.detail.value.outtime
      
          wx.request({
            url: 'http://47.92.245.109:8080/addmessage',
            method: "POST",
            data: {
              cardid: data.detail.value.cardid,
              houseid: data.detail.value.houseid,
              name: data.detail.value.name,
              temperature: data.detail.value.temperature,
              in_orout: data.detail.value.in_orout,
              outtime: that.data.time
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            success: function (res) {
              wx.showToast({
 
                title: '提交成功',
                 
                icon: 'success',
                 
                duration: 2000,
              
   
            })
            }
     
          })
     
     
     
        
      }
      
  ,

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  getScancode: function () {
    var _this = this;
    
    wx.scanCode({
      success: (res) => {
        var result = res.result;
 
        _this.setData({
          result: result,
 
        })
        var that = this;
        wx.request({
          url: 'http://47.92.245.109:8080/find',
     
          data: {
            openid:result
           },
          header: {
            'content-type': 'application/json' //默认值
          },
          success: function (res) {
            
          
            console.log(res.data);
              that.setData({
                list:res.data
              
              })
        }
      })
    }
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})